(defmeth mosaic-proto :prepare ()
  (let* ((cells (send self :cells))
         (levels (send self :levels))
         (gaps (send self :gaps))
         (ways (send self :ways))
         (total (send self :total)))
    (cond 
      ((> (length cells) 1)
       (cond 
         ((not (send self :bar))  ;my modification does not work with bar graphs
          (setf odds (which (mapcar 'oddp (iseq ways))))
         ; (when odds (setf gapsodds (*  1 (select (send self :levels) odds) (select (list 5 1 1 1) odds)))
         ; (setf (select gaps odds) (select gapsodds (iseq (length odds)))))
          (setf evens (which (mapcar 'evenp (iseq ways))))
          (setf gapsevens (* 1 (select (send self :levels) evens) (select (list 5 1 1 1) evens)))
         ;(setf (select gaps evens) (select gapsevens (iseq (length evens))))
          (setf counter 0)
          (setf listways (iseq ways))
          ;(setf listways 
               ; (remove 'nil
                       ; (combine 
                        ; (select listways (which (mapcar 'evenp (iseq ways))))
                        ; (select listways (which (mapcar 'oddp (iseq ways))))))) removed to recover standard mosaic plots pv 2008
         ;(setf cells (select cells (send self :correct-position-cells))) removed to recover standard mosaic plots pv 2008
          (dolist (i listways)
                  (let* ((current-levels (elt levels i))
                         (current-gap (elt gaps i))
                         (split (if (evenp i) 0 1))
                         (stem (reduce #'* (select levels (select listways (iseq counter (1- ways))))))
                         (leaf (/ total (reduce #'* (select levels (select listways (iseq 0 counter))))))
                         (nr-ls (split-list cells stem))
                         (dr-ls (mapcar #'sum (split-list cells stem)))
                         (divis-result (/0 nr-ls dr-ls 0))
                         (uncut-ls (combine (first divis-result)))
                         (cut-ls (split-list uncut-ls leaf))
                         (ps (mapcar #'sum cut-ls))
                         (mx (send self :original-mx))
                         (bad-mx
                          (send self :matrix-span mx ps 
                                current-levels current-gap split)) ;ng if ways=1
                         (good-mx (send self :clean-matrix bad-mx)))
                    (send self :original-mx good-mx)
                    (setf counter (1+ counter))
                    ))

          )
         (t (dotimes (i ways t)
                     (let* ((current-levels (elt levels i))
                            (current-gap (elt gaps i))
                            (split (if (evenp i) 0 1))
                            (stem (reduce #'* (select levels (iseq i (- ways 1)))))
                            (leaf (/ total (reduce #'* (select levels (iseq 0 i)))))
                            (nr-ls (split-list cells stem))
                            (dr-ls (mapcar #'sum (split-list cells stem)))
                            (divis-result (/0 nr-ls dr-ls 0))
                            (uncut-ls (combine (first divis-result)))
                            (cut-ls (split-list uncut-ls leaf))
                            (ps (mapcar #'sum cut-ls))
                            (mx (send self :original-mx))
                            (bad-mx
                             (send self :matrix-span mx ps 
                                   current-levels current-gap split)) ;ng if ways=1
                            (good-mx (send self :clean-matrix bad-mx)))
                       (send self :original-mx good-mx)
                       )))))
       (t (send self :original-mx (bind-rows (send self :original-mx)))))
    (send self :draw-mx (send self :original-mx))
    (send self :rect-centers 
          (floor (/ (mapcar #'(lambda (vector) 
                                (let ((xywh (coerce vector 'list)))
                                  (list (+ (* 2 (first xywh)) (third xywh))
                                        (+ (* 2 (second xywh)) (fourth xywh)))))
                            (row-list (send self :draw-mx))) 2)))
    ))